<?php

/**
 * Created by PhpStorm.
 * Author: ls
 * Time: 2023/9/20 11:14
 * Desc: 邮轮
 */
class Model_Api_V2_Ship extends ORM
{
    /**
     *  订单扩展信息
     * @param $order
     * @return array
     */
    public static function order_attach($order)
    {
        $data = array();
        //航线附加产品信息
        $attach_info = DB::select()->from('member_order_child')
            ->where('pid', '=', $order['id'])
            ->execute()
            ->current();

        $attach = unserialize($attach_info['attachinfo']);
        foreach ($attach as &$item) {
            $item['name'] = DB::select()->from('ship_line_additional')
                ->where('id', '=', $item['id'])
                ->execute()
                ->get('name');
        }
        $data['attach']   = $attach;
        $voyage             = DB::select()->from('ship_line_voyage')
            ->where('id', '=', $attach_info['voyageid'])
            ->execute()
            ->current();
        $suit               = DB::select()->from('ship_line_suit')
            ->where('id', '=', $attach_info['suitid'])
            ->execute()
            ->current();
        $ship_name          = DB::select()->from('ship')
            ->where('id', '=', $suit['shipid'])
            ->execute()
            ->get('title');
        $line               = DB::select('startcity', 'finaldestid')->from('ship_line')
            ->where('id', '=', $voyage['lineid'])
            ->execute()
            ->current();
        $startcity          = DB::select()->from('destinations')
            ->where('id', '=', $line['startcity'])
            ->execute()
            ->get('kindname');
        $destcity           = DB::select()->from('destinations')
            ->where('id', '=', $line['finaldestid'])
            ->execute()
            ->get('kindname');
        $room               = DB::select()->from('ship_room')
            ->where('id', '=', $suit['roomid'])
            ->execute()
            ->get('title');
        $lineInfo           = array(
            'date' => $order['usedate'],
            'ship' => $ship_name,
            'start_time' => $voyage['start_time'],
            'end_time' => $voyage['end_time'],
            'startcity' => $startcity,
            'destcity' => $destcity,
            'peoplenum' => $attach_info['peoplenum'],
            'dingnum' => $order['dingnum'],
            'room' => $room,
        );
        $data['lineInfo'] = $lineInfo;
        //人群
        $data['people'] = unserialize($attach_info['crowd']);
        //楼层
        $floor = unserialize($attach_info['floor']);

        $data['floors']   = $floor;
        $data['price']    = $order['pay_price'];
        $data['payprice'] = $order['pay_price'];

        return $data;
    }

}